<?php
  require_once("include/fns.inc");
  if ($_GET['logout']==1) {
    unset($_SESSION['valid_login']);
  }
?>
<table width="100%">
<tr>
  <td class="style3">
  	<a href="frontpage.php">Home</a> >
    <a href="rector.php">TPU</a>
    <?php
      if (isset($_GET['d_id'])) {
        $link = connect_to_db('', 'admin_xbq', 'nihao', 'test');
        $sql = "select d_short_name from department where department.depart_ID='".$_GET['d_id']."';";
        $result = mysql_query($sql) or die('Query failed topl: ' . mysql_error());
        $line = mysql_fetch_array($result, MYSQL_ASSOC);
        echo '> <a href="rector.php?d_id='.$_GET['d_id'].'">'.$line['d_short_name'].'</a>';
      }
      if (isset($_GET['s_id'])) {
        $link = connect_to_db('', 'admin_xbq', 'nihao', 'test');
        $sql = "select depart_ID, sr_short_name from staffroom where sr_ID='".$_GET['s_id']."';";
        $result = mysql_query($sql) or die('Query failed topl: ' . mysql_error());
        $line = mysql_fetch_array($result, MYSQL_ASSOC);
        
        $sql1 = "select d_short_name from department where depart_ID='".$line['depart_ID']."';";
        $res = mysql_query($sql1) or die('Query failed topl: ' . mysql_error());
        $line1 = mysql_fetch_array($res, MYSQL_ASSOC);
        
        echo ' > <a href="rector.php?d_id='.$line['depart_ID'].'">'.$line1['d_short_name'].'</a>';
        echo ' > <a href="rector.php?s_id='.$_GET['s_id'].'">'.$line['sr_short_name'].'</a>';
      }
      if (isset($_GET['user_id'])) {
        $link = connect_to_db('', 'admin_xbq', 'nihao', 'test');
        
        $sql0 = "select sr_ID, user_name from user where user_ID='".$_GET['user_id']."';";
        $result0 = mysql_query($sql0) or die('Query failed topl: ' . mysql_error());
        $line0 = mysql_fetch_array($result0, MYSQL_ASSOC);

        $sql1 = "select depart_ID, sr_short_name from staffroom where sr_ID='".$line0['sr_ID']."';";
        $result1 = mysql_query($sql1) or die('Query failed topl: ' . mysql_error());
        $line1 = mysql_fetch_array($result1, MYSQL_ASSOC);
        
        $sql2 = "select d_short_name from department where depart_ID='".$line1['depart_ID']."';";
        $result2 = mysql_query($sql2) or die('Query failed topl: ' . mysql_error());
        $line2 = mysql_fetch_array($result2, MYSQL_ASSOC);
        
        echo ' > <a href="rector.php?d_id='.$line1['depart_ID'].'">'.$line2['d_short_name'].'</a>';
        echo ' > <a href="rector.php?s_id='.$line0['sr_ID'].'">'.$line1['sr_short_name'].'</a>';
        echo ' > <a href="rector.php?user_id='.$_GET['user_id'].'">'.$line0['user_name'].'</a>';
      }
    ?>
  </td>
  <td class="style3" align="right">
  	<a href="<?echo $_SERVER['PHP_SELF'];?>?logout=1">Sign out</a>
  </td>
</tr>
</table>

      <?php
/*
        if (isset($_SESSION['valid_login'])) {
          $link = connect_to_db('', 'admin_xbq', 'nihao', 'test');
          $sql = "select user_name from user where user.login='".$_SESSION['valid_login']."';";
          $result = mysql_query($sql) or die('Query failed2: ' . mysql_error());
          $line = mysql_fetch_array($result, MYSQL_ASSOC);
          echo $line['user_name'];
          mysql_free_result($result);
          mysql_close($link);
        }
*/
      ?>
